home *** CD-ROM | disk | FTP | other *** search
- /*
- * This sample applications demonstrates how to sort a file using the
- * Sort Solution Library
- *
- * This source code is only intended as a supplement to the Sort Solution user
- * documentation and related electronic documentation provided with the library.
- * See these sources for detailed information regarding the Sort Solution product.
- *
- *
- * Copyright ⌐ 1997,98 Mario M. Westphal
- * All Rights reserved
- */
-
- // The standard stuff
- #include <stdlib.h>
- #include <stdio.h>
-
- // The Sort Solution headers
- #include "..\..\Include\sortsoli.h"
-
-
- // We sort a text file (each line delimited with a carriage return/linefeed pair)
- // using the key type String on the whole line...
- #define PROFILESTRING "INPUTFILE(input.txt)\r\n" \
- "OUTPUTFILE(output.txt)\r\n" \
- "FILETYPE(DELIMITED,\";\",\"0x0D,0x0A\")\r\n" \
- "KEY(String,ASC,1,0,0)\r\n"
-
-
- // Print an error message using SSIGetErrorMessage
- void PrintError(SORTSOL_ERROR Code)
- {
- char msg[512];
- unsigned len = sizeof(msg);
- SSIGetErrorMessage(Code,msg,&len);
- printf("\n%s\n",msg);
- }
-
-
- // M A I N
- int main(int argc, char *argv[])
- {
- SSIH ssihandle; // The Sort Solution handle
- SORTSOL_ERROR result; // Stores results from the API calls
- SORTSOL_CMDFILESTATUS cmdstat;
-
- // (1) Create a sort instance from the command string
- result = SSICreateFromCommandString(&ssihandle,PROFILESTRING,&cmdstat);
-
- // If there is an error at this stage, something is wrong with
- // the profile string
- if (result != SOSOERR_SUCCESS) {
- PrintError(result);
- if (cmdstat.LineNo > 0) {
- printf("Error in line %d\n",cmdstat.LineNo);
- printf("'%s'\n",cmdstat.ErrLine);
- }
- return -1;
- }
- else {
- // Run the sort
- result == SSISort(ssihandle);
-
- // Free the handle
- SSIFree(ssihandle);
- }
-
- if (result != SOSOERR_SUCCESS) {
- PrintError(result);
- return -1;
- }
- else {
- printf("\nSort completed.\n");
- return 0;
- }
- }
-